//
//  UserViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/11.
//

import Foundation
import LeanCloud
import SwiftUI

//废弃了
class AiManager : BaseViewModel {
    static let shared = AiManager()

    func getAiCustom() -> [String:String]? {
        let dict = try? fromJson(AppStorageManager.shared.aiCustom,  [String:String].self)
        return dict
    }
    
    func getAiCustom(key: String) -> AiModelCustomBean {
        let dict =  getAiCustom()
        guard let json = dict?[key] else { return AiModelCustomBean() }

        return (try? fromJson(json, AiModelCustomBean.self)) ?? AiModelCustomBean()
    }
    
    func getAiCustom2(key: String) -> AiModelCustomBean? {
        let dict =  getAiCustom()
        guard let json = dict?[key] else { return nil }

        return (try? fromJson(json, AiModelCustomBean.self)) ?? nil
    }
    
    func saveAiCustom(key: String, bean: AiModelCustomBean, invoke: @escaping () -> Void) {
        var dict =  getAiCustom() ?? [:]
        dict[key] = toJson(bean)
        AppStorageManager.shared.aiCustom = toJson(dict: dict)
        showLog("自定义ai模型：\(AppStorageManager.shared.aiCustom)")
        invoke()
    }
    
    func isCustomAi(key: String) -> Bool{
        let bean = getAiCustom(key: key)
        return bean.host?.isEmpty == false && bean.token?.isEmpty == false  && bean.model?.isEmpty == false
    }
  
}
